
#include "stdc/stdc++.h"
class House
{
   public:
    void Add(const std::string &part)
    {
        m_part += part;
    }

    std::string Show()
    {
        return m_part;
    }

   private:
    std::string m_part;
};

class HouseBuilder
{
   public:
    House *GetResult()
    {
        return pHouse;
    }
    HouseBuilder()
    {
        pHouse = new House();
    }
    virtual ~HouseBuilder()
    {
        delete pHouse;
    }

   protected:
    House *pHouse;

   public:
    virtual void BuildPart1() = 0;
    virtual void BuildPart2() = 0;
    virtual bool BuildPart3() = 0;
    virtual void BuildPart4() = 0;
    virtual void BuildPart5() = 0;
};

class StoneHouse : public House
{};

class StoneHouseBuilder : public HouseBuilder
{
   public:
    void BuildPart1() override
    {
        pHouse->Add("_1_");
    }
    void BuildPart2() override
    {
        pHouse->Add("_2_");
    }
    bool BuildPart3() override
    {
        pHouse->Add("_3_");
        return true;
    }
    void BuildPart4() override
    {
        pHouse->Add("_4_");
    }
    void BuildPart5() override
    {
        pHouse->Add("_5_");
    }
};

class HouseDirector
{

   public:
    HouseBuilder *pHouseBuilder;

    HouseDirector(HouseBuilder *pHouseBuilder)
    {
        this->pHouseBuilder = pHouseBuilder;
    }

    House *Construct()
    {
        pHouseBuilder->BuildPart1();

        for (int i = 0; i < 4; i++)
        {
            pHouseBuilder->BuildPart2();
        }

        bool flag = pHouseBuilder->BuildPart3();

        if (flag)
        {
            pHouseBuilder->BuildPart4();
        }

        pHouseBuilder->BuildPart5();

        return pHouseBuilder->GetResult();
    }
};

int main()
{
    HouseBuilder *builder = new StoneHouseBuilder();
    HouseDirector house_director = HouseDirector(builder);

    std::string house = house_director.Construct()->Show();
    std::cout << "house builder : " << house << std::endl;
    delete builder;
    return 0;
}
